ThongTinNhanVienFieldSet = Ext.extend(Ext.form.FieldSet, {
	autoHeight : true,
	collapsible: false,
	collapsed : false,
	height : 260,
	width : 500,
	title : lang.text.nv.thongTinNhanVien,
	layout : 'customizedlayout',
	labelWidth : 100,
	
	haveMaNv : true,// Allow to render maNv field.
	initDataUrl : 'nhanVien/initData',
	
	parentContainer : null, // Must have method afterInitData if parentContainer != null
	
	initComponent : function() {
		var fieldPlugin = new CustomizedFieldPlugin();
		this.maNv = new Ext.form.TextField({
			name : "maNv",
			fieldLabel : lang.text.nv.maNV,
			anchor : '100%',
			maxLength : 15,
			style : {
				textTransform : 'uppercase'
			},
			selectOnFocus : true,
			allowBlank : false,
			mandatory : true,
			plugins : fieldPlugin
		});
		
		this.hoTen = new Ext.form.TextField({
			name : "hoTen",
			fieldLabel : lang.text.nv.hoTen,
			anchor : '100%',
			selectOnFocus : true,
			allowBlank : false,
			maxLength : 50,
			mandatory : true,
			plugins : fieldPlugin
		});
		
		this.password = new Ext.form.TextField({
			name : "password",
			fieldLabel : lang.text.nv.password,
			anchor : '100%',
			selectOnFocus : true,
			maxLength : 8,
			inputType: 'password',
			plugins : fieldPlugin
		});
		
		this.loaiNv = new Ext.form.ComboBox({
			name : 'loaiNv',
			hiddenName : 'loaiNv-id',
            fieldLabel : lang.text.nv.loaiNhanVien,
            anchor  : '100%',
            forceSelection : true,
            mode : 'local',
            triggerAction : 'all',
            valueField : 'id',
            displayField : 'loaiNv',
            selectOnFocus : true,
            allowBlank : false,
			mandatory : true,
            store : new Ext.data.JsonStore({
                fields : ['id', 'loaiNv']
            }),
			plugins : fieldPlugin
		});
		
		this.doiTruong = new Ext.form.ComboBox({
			name : 'doiTruong',
			hiddenName : 'doiTruong-id',
            fieldLabel : lang.text.hd.doiTruong,
            anchor  : '100%',
            forceSelection : true,
            selectOnFocus : true,
            mode : 'local',
            triggerAction : 'all',
            valueField : 'id',
            displayField : 'maNv',
            disabled : true,
            store : new Ext.data.JsonStore({
            	url : 'nhanVien/loadDoiTruong',
            	autoLoad : true,
                fields : ['id', 'maNv']
            }),
			plugins : fieldPlugin
		});
		
		this.daKichHoat = new Ext.form.Checkbox({
			name : 'kichHoat',
			checked : this.haveMaNv,
			fieldLabel : lang.text.nv.daKichHoat
		});
		
		this.items = [this.haveMaNv ? this.maNv : [], this.hoTen,this.password, this.loaiNv ,this.doiTruong,this.daKichHoat];
		ThongTinNhanVienFieldSet.superclass.initComponent.call(this);
	},
	
	afterRender : function() {
		ThongTinNhanVienFieldSet.superclass.afterRender.call(this);
		
		this.initData();
		this.doiTruong.on('expand', function() {
			this.doiTruong.store.load();	
		}, this);
		this.loaiNv.on('select', this.allowToSelectDoiTruong, this);
	},
	
	allowToSelectDoiTruong : function(){
		if(this.loaiNv.getValue() == 'BAN_HANG'/*Should change with data in LoaiNhanVien*/){
			this.doiTruong.enable();
		} else {
			this.doiTruong.disable();
			this.doiTruong.setValue("");
		}
	},
	
	initData : function(){
		Ext.Ajax.request({
            url : this.initDataUrl,
            method : 'GET',
            scope : this,
            success : function(response, opts){
                var result = Ext.decode(response.responseText); 
                this.loaiNv.store.loadData(result.loaiNv);
                if(this.parentContainer){//If we have parentContainer, it means we need to process more with result data.
                	this.parentContainer.afterInitData(result);
                }
            }, 
            failure : Ext.emptyFn
        }, this);
	}
});